﻿using Abp.EntityFrameworkCore;
using CheryABP.AdoContext;
using CheryABP.Person;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CheryABP.EntityFrameworkCore.Repositories
{
    public class PersonRepository: CheryABPRepositoryBase<People,Int32>, IPersonRepository
    {
        public PersonRepository(IDbContextProvider<CheryABPDbContext> dbContextProvider) : base(dbContextProvider)
        {
        }

        public List<People> GetPersons()
        {
            //在仓储方法中，不用处理数据库连接、DbContext和数据事务，ABP框架会自动处理。
            //GetAll() 返回一个 IQueryable<T>接口类型
            var query = GetAll();
            return query.OrderByDescending(p => p.Id).ToList();
        }

        public DataTable GetPersonByID(int id)
        {
            DataTable query = SqlServerConn.Query($"select*from Person where id ={id}").Tables[0];
            return query;
        }

        public DataTable GetPersonDep()
        {
            DataTable query = SqlServerConn.Query($"select t1.*,t2.department from Person t1 join Department t2 ON t1.department_id = t2.id").Tables[0];
            return query;
        }
    }
}
